/*
 * @Description: 从一维数组中找到节点的父祖节点
 * @Author: 0001101185/DingYi
 * @Date: 2023-12-28 17:41:56
 * @LastEditTime: 2024-01-04 14:11:53
 * @LastEditors: 0001101185/DingYi
 */
const findParents = (item, arr, options = { id: 'id', parentId: 'parentId', root: 0 }) => {
  let _parents = [];
  return (function findParent (item) {
    if (item[options.parentId] === options.root) return _parents;
    const parent = arr.find(i => i[options.id] === item[options.parentId]);
    if (parent) {
      _parents.push(parent);
      return findParent(parent);
    } else {
      return _parents;
    }
  })(item);
};

export {
  findParents,
};